//如果图片要跨域提交，那么swfupload.swf要和提交的url在统一域名下
var Flash = (function () {
    //flash检查
    function flashChecker() {
        var hasFlash = false;  //是否安装了flash
        var flashVersion = 0; //flash版本
        var isIE = jQuery.support.msie == true; //是否IE浏览器

        if (isIE) {
            try {
                var swf = new ActiveXObject('ShockwaveFlash.ShockwaveFlash');
                if (swf) {
                    hasFlash = true;
                    VSwf = swf.GetVariable("$version");
                    flashVersion = parseInt(VSwf.split(" ")[1].split(",")[0]);
                }
            } catch (ex) {
                hasFlash = false;
                flashVersion = 0;
            }
        } else {
            if (navigator.plugins && navigator.plugins.length > 0) {
                var swf = navigator.plugins["Shockwave Flash"];
                if (swf) {
                    hasFlash = true;
                    var words = swf.description.split(" ");
                    for (var i = 0; i < words.length; ++i) {
                        if (isNaN(parseInt(words[i]))) continue;
                        flashVersion = parseInt(words[i]);
                    }
                }
            }
        }
        return { f: hasFlash, v: flashVersion };
    }

    //初始化flash上传控件
    function initFlash(option) {
        var obj = flashChecker();
        if (!obj.f || obj.v < 10) {
            //$("#step_first").click(function () {
                if (!obj.f) {
                    art.tip.danger("该功能需要flash的支持(版本10及以上)，请先下载安装flash。");
                }
                else if (obj.v < 10) {
                    art.tip.danger("flash 版本过低(要求版本10及以上)，请更新flash。");
                }
            //});
            App.blockUI({target: $("#note"), iconOnly: true});
            return false;
        }

        new SWFUpload({
            // Backend Settings
            upload_url: option.upload_url,
            upload_type: option.upload_type,
            post_params: option.post_params,

            // File Upload Settings
            file_size_limit: option.file_size_limit,
            file_types: option.file_types,
            file_types_description: option.file_types_description,
            file_upload_limit: option.file_upload_limit,

            // The event handler functions are defined in handlers.js
            file_queue_error_handler: fileQueueError,
            upload_start_handler: uploadStart,
            upload_progress_handler: uploadProgress,
            upload_error_handler: uploadError,
            upload_success_handler: uploadSuccess,
            upload_complete_handler:uploadComplete,
            file_dialog_complete_handler: fileDialogComplete,

            // Button settings
            button_image_url: option.button_image_url,
            button_action: option.button_action,
            button_placeholder_id: "spanButtonPlaceholder_" + option.upload_type,
            button_width: 226,
            button_height: 36,
            button_text: option.button_text,
            button_text_style: option.button_text_style,
            button_text_top_padding: 6,
            //button_text_left_padding: 5,
            button_cursor: SWFUpload.CURSOR.HAND,
            button_window_mode: SWFUpload.WINDOW_MODE.TRANSPARENT,

            button_disabled: option.button_disabled,
            mouse_click_handler: function(){mouseClick(option.upload_type)},
            
            flash_url: option.flash_url,
            flash9_url: option.flash9_url,
            debug: false,
            custom_settings: {
                upload_success_handler: uploadSuccess_Callback
            }
        });
    }

    return {
        init: function (option) {
            initFlash(option);
        }
    };

})();